package com.sumainfor.pc.market.controller.rentadviser;

import com.sumainfor.common.entity.ParentDeptVo;
import com.sumainfor.common.entity.SysUserVo;
import com.sumainfor.common.util.ContextUtils;
import com.sumainfor.common.util.JsonResult;
import com.sumainfor.common.utlis.PageUtils;
import com.sumainfor.common.utlis.Pager;
import com.sumainfor.pc.market.feign.Zfeign.ZzuulFeign;
import com.sumainfor.pc.market.service.RdWorderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @Date 2018年11月7日
 * @Describe 工程部查询房源配置
 */
@RestController
@RequestMapping("/rentadviser/RdWorderController")
public class RdWorderController implements Serializable {
    @Autowired
    private RdWorderService rdWorderService;
    @Autowired
    private ZzuulFeign zzuulFeign;
    /**
     *查询今天需待看的工单
     * @param
     * @return
     */
    @GetMapping("/getWorderListToday")
    public JsonResult getTenantAskListToday(@RequestParam Map<String,Object>params, Pager pager){
        String uid= ContextUtils.getUserId();
        if (uid!=null){
            params.put("OperId",uid);
        }
        System.out.println("OperId================================:"+ContextUtils.getUserId());
        JsonResult result=new JsonResult();
        pager.setPagerNecessary(params, pager);
        PageUtils pageUtils = new PageUtils();
        Integer cout=rdWorderService.getWorderListCountToday(params);
        if(cout==0){
            return pageUtils.getJsonResult(new ArrayList<Map<String,Object>>(), params,cout);
        }
        List<Map<String,Object>>getCommunityList=rdWorderService.getWorderListToday(params);
        result=pageUtils.getJsonResult(getCommunityList, params, cout);
        return result;
    }
    /**
     *查询未来需待看的工单
     * @param
     * @return
     */
    @GetMapping("/getTenantAskListFuture")
    public JsonResult getRepairList(@RequestParam Map<String,Object>params, Pager pager){
        String uid= ContextUtils.getUserId();
        if (uid!=null){
            params.put("OperId",uid);
        }
        JsonResult result=new JsonResult();
        pager.setPagerNecessary(params, pager);
        PageUtils pageUtils = new PageUtils();
        Integer cout=rdWorderService.getWorderListCountFuture(params);
        if(cout==0){
            return pageUtils.getJsonResult(new ArrayList<Map<String,Object>>(), params,cout);
        }
        List<Map<String,Object>>getCommunityList=rdWorderService.getWorderListFuture(params);
        result=pageUtils.getJsonResult(getCommunityList, params, cout);
        return result;
    }
    /**
     *查询公共转单池
     * @param
     * @return
     */
    @GetMapping("/getWorderListPublic")
    public JsonResult getWorderListPublic(@RequestParam Map<String,Object>params, Pager pager){
        String uid= ContextUtils.getUserId();
        if (uid!=null){
            params.put("OperId",uid);
        }
        JsonResult result=new JsonResult();
        pager.setPagerNecessary(params, pager);
        PageUtils pageUtils = new PageUtils();
        Integer cout=rdWorderService.getWorderListCountPublic(params);
        if(cout==0){
            return pageUtils.getJsonResult(new ArrayList<Map<String,Object>>(), params,cout);
        }
        List<Map<String,Object>>getCommunityList=rdWorderService.getWorderListPublic(params);
        result=pageUtils.getJsonResult(getCommunityList, params, cout);
        return result;
    }
    /**
     *查询私有转单池
     * @param
     * @return
     */
    @GetMapping("/getWorderListPrivate")
    public JsonResult getWorderListPrivate(@RequestParam Map<String,Object>params, Pager pager){
        String uid= ContextUtils.getUserId();
        if (uid!=null){//传入当前登录人的编号
            params.put("TurnSysId",uid);
        }
        JsonResult result=new JsonResult();
        pager.setPagerNecessary(params, pager);
        PageUtils pageUtils = new PageUtils();
        Integer cout=rdWorderService.getWorderListCountPrivate(params);
        if(cout==0){
            return pageUtils.getJsonResult(new ArrayList<Map<String,Object>>(), params,cout);
        }
        List<Map<String,Object>>getCommunityList=rdWorderService.getWorderListPrivate(params);
        result=pageUtils.getJsonResult(getCommunityList, params, cout);
        return result;
    }
    /**
     *查询租客维护
     * @param
     * @return
     */
    @GetMapping("/getWorderListMaintain")
    public JsonResult getWorderListMaintain(@RequestParam Map<String,Object>params, Pager pager){
        String uid= ContextUtils.getUserId();
        if (uid!=null){
            params.put("SetId",uid);
        }
        JsonResult result=new JsonResult();
        pager.setPagerNecessary(params, pager);
        PageUtils pageUtils = new PageUtils();
        Integer cout=rdWorderService.getWorderListCountMaintain(params);
        if(cout==0){
            return pageUtils.getJsonResult(new ArrayList<Map<String,Object>>(), params,cout);
        }
        List<Map<String,Object>>getCommunityList=rdWorderService.getWorderListMaintain(params);
        result=pageUtils.getJsonResult(getCommunityList, params, cout);
        return result;
    }
    /**
     *查询已带看工单
     * @param
     * @return
     */
    @GetMapping("/getWorderListAlready")
    public JsonResult getWorderListAlready(@RequestParam Map<String,Object>params, Pager pager){
        String uid= ContextUtils.getUserId();
        if (uid!=null){
            params.put("OperId",uid);
        }
        JsonResult result=new JsonResult();
        pager.setPagerNecessary(params, pager);
        PageUtils pageUtils = new PageUtils();
        Integer cout=rdWorderService.getWorderListCountAlready(params);
        if(cout==0){
            return pageUtils.getJsonResult(new ArrayList<Map<String,Object>>(), params,cout);
        }
        List<Map<String,Object>>getCommunityList=rdWorderService.getWorderListAlready(params);
        result=pageUtils.getJsonResult(getCommunityList, params, cout);
        return result;
    }
    /**
     *查询换房申请
     * @param
     * @return
     */
    @GetMapping("/getWorderListApply")
    public JsonResult getWorderListApply(@RequestParam Map<String,Object>params, Pager pager){
        String uid= ContextUtils.getUserId();
        if (uid!=null){
            params.put("OperId",uid);
        }
        JsonResult result=new JsonResult();
        pager.setPagerNecessary(params, pager);
        PageUtils pageUtils = new PageUtils();
        Integer cout=rdWorderService.getWorderListCountApply(params);
        if(cout==0){
            return pageUtils.getJsonResult(new ArrayList<Map<String,Object>>(), params,cout);
        }
        List<Map<String,Object>>getCommunityList=rdWorderService.getWorderListApply(params);
        result=pageUtils.getJsonResult(getCommunityList, params, cout);
        return result;
    }
    /**
     * 创建工单
     */
    @PostMapping("/addWorderMaintain")
    public JsonResult addWorderMaintain(@RequestBody Map<String,Object>params){
        return rdWorderService.addWorderMaintain(params);
    }
    /**
     * 创建工单
     */
    @PostMapping("/addWorder")
    public JsonResult addWorder(@RequestBody Map<String,Object>params){
        return rdWorderService.addWorder(params);
    }
    /**
     * 租客维护点击创建工单
     */
    @PostMapping("/addWorderTenant")
    public JsonResult addWorderTenant(@RequestBody Map<String,Object>params){
        return rdWorderService.addWorderTenant(params);
    }
    /**
     * 接受转单
     */
    @PostMapping("/addWorderOrWorderInfo")
    public JsonResult addWorderOrWorderInfo(@RequestBody Map<String,Object>params){
        return rdWorderService.addWorderOrWorderInfo(params);
    }
    /**
     *
     * 查询服务中心下的全部角色列表，租赁顾问查询转单的伙伴
     */
    @GetMapping("/getWoSaleIdList")
    public JsonResult getWoSaleIdList(@RequestParam Map<String,Object> params){
        //获取当前登录人的服务中心编号
//        SysUserVo userVo = ContextUtils.getSysUser();
//        ParentDeptVo vo = null;
//        for (int i = 0; i < userVo.getLength(); i++) {
//            ParentDeptVo vo1 = userVo.getParentDeptVo();
//            if (vo1.getType().equals(3)) {
//                vo = vo1;
//                break;
//            }
//        }
//        if (vo!=null){
//            params.put("area_id",vo.getDeptId());//当前登录人的服务中心编号
//            System.out.println("area_id:"+vo.getDeptId());
//        }
        params.put("user_id",ContextUtils.getUserId());
        return zzuulFeign.getWoSaleIdList(params);
    }
    /**
     *
     * 获取58集中式房源预约信息列表
     */
    @PostMapping("/api_order_info_get")
    public JsonResult api_order_info_get(@RequestBody Map<String,Object> params) {
        return rdWorderService.api_order_info_get(params);
    }
}
